package com.tx.studentManager.model;

import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

/**
 * 系统用户表 添加动态插入和动态更新
 */
@Entity
@Table(name = "user", catalog = "studentManager")
@DynamicInsert(true)
@DynamicUpdate(true)
public class User extends BaseModel {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "userId", nullable = false)
	private Integer userId;

	/**
	 * 角色Id,级联更新、刷新，懒加载
	 */
	@ManyToOne(fetch = FetchType.LAZY, cascade = {CascadeType.REFRESH,CascadeType.MERGE })
	@JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "userId"), inverseJoinColumns = @JoinColumn(name = "roleId"))
	private Role role;

	@Column(name = "username", length = 18, nullable = false)
	private String userName;

	@Column(name = "password", length = 18, nullable = false)
	private String password;

	@Column(name = "sex", length = 4, nullable = true)
	private String sex;

	@Column(name = "nickname", length = 16, nullable = true)
	private String nickName;

	@Column(name = "phone", length = 15, nullable = true)
	private String phone;

	@Column(name = "email", length = 30, nullable = false)
	private String email;

	@Column(name = "age", nullable = true)
	private Integer age;

	@Column(name = "createDate", length = 50, nullable = false)
	private Date createDate;

	@Column(name = "activated",nullable=false)
	private Integer activated;

	public Integer getActivated() {
		return activated;
	}

	public void setActivated(Integer activated) {
		this.activated = activated;
	}

	public User() {

	}

	public User(String userName, String password, String sex) {
		this.userName = userName;
		this.password = password;
		this.sex = sex;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer id) {
		this.userId = id;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

}
